package javaweb.filter;
import javaweb.utility.JDBCUnility;
import javax.servlet.*;
import java.io.IOException;
/**
 * @author shkstart
 * @creat -08-11 21:16
 */
public class TransactionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            filterChain.doFilter(servletRequest,servletResponse);
            JDBCUnility.closeAndCommit();
        } catch (IOException e) {
            JDBCUnility.closeAndRollback();
            e.printStackTrace();
            throw  new RuntimeException(e);
        }
    }
    @Override
    public void destroy() {

    }
}
